﻿<Window x:Class="COMRegistryBrowser.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:COMRegistryBrowser"
        xmlns:dgx="clr-namespace:DataGridExtensions;assembly=DataGridExtensions"
        xmlns:win32="clr-namespace:Microsoft.Win32;assembly=mscorlib"
        Title="COM Registry Browser" TextOptions.TextFormattingMode="Display"
        >
  <Window.DataContext>
    <src:Browser/>
  </Window.DataContext>

  <Window.Resources>

    <dgx:RegexContentFilterFactory x:Key="RegexContentFilterFactory"/>
    <dgx:SimpleContentFilterFactory x:Key="SimpleContentFilterFactory"/>

    <ContextMenu x:Key="ContextMenu">
      <MenuItem Header="Unregister" Command="{Binding Path=UnregisterCommand}" VerticalContentAlignment="Center">
        <MenuItem.Icon>
          <Path Data="M0,0 L8,8 M0,8 L8,0" Stroke="Red" StrokeThickness="2" HorizontalAlignment="Center"/>
        </MenuItem.Icon>
      </MenuItem>
    </ContextMenu>

    <Style TargetType="DataGrid">
      <Setter Property="AlternatingRowBackground" Value="LightGreen"/>
      <Setter Property="HorizontalGridLinesBrush" Value="LightGray"/>
      <Setter Property="VerticalGridLinesBrush" Value="LightGray"/>
      <Setter Property="ItemsSource" Value="{Binding Path=ItemsView}"/>
      <Setter Property="dgx:DataGridFilter.ContentFilterFactory" Value="{StaticResource RegexContentFilterFactory}"/>
      <Setter Property="src:MultiSelectorExtensions.SelectionBinding" Value="{Binding Path=SelectedItems}"/>
      <Setter Property="ContextMenu" Value="{StaticResource ContextMenu}"/>
      <EventSetter Event="Loaded" Handler="DataGrid_Loaded"/>
      <EventSetter Event="MouseDoubleClick" Handler="DataGrid_MouseDoubleClick"/>
    </Style>

  </Window.Resources>

  <Grid>
    <Grid>
      <TabControl Margin="0,5,0,0">
        <TabItem Header="Servers">
          <Grid DataContext="{Binding Path=ServerCollection}">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="2*"/>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <DataGrid x:Name="serversGrid" Grid.Column="0" dgx:DataGridFilter.IsAutoFilterEnabled="True"/>
            <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center"/>
            <Grid Grid.Column="2">
              <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
              </Grid.RowDefinitions>
              <DockPanel Grid.Row="0" DataContext="{Binding Path=InterfaceCollection}">
                <TextBlock DockPanel.Dock="Top" Margin="4" Text="Interfaces marshalled by the selected servers:"/>
                <DataGrid/>
              </DockPanel>
              <GridSplitter Grid.Row="1" Height="3" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
              <DockPanel Grid.Row="2" DataContext="{Binding Path=TypeLibraryCollection}">
                <TextBlock DockPanel.Dock="Top" Margin="4" Text="Type libraries in the modules of the selected server:"/>
                <DataGrid/>
              </DockPanel>
            </Grid>
          </Grid>
        </TabItem>

        <TabItem Header="Interfaces">
          <Grid DataContext="{Binding Path=InterfaceCollection}">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="2*"/>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <DataGrid x:Name="interfacesGrid" Grid.Column="0" dgx:DataGridFilter.IsAutoFilterEnabled="True"/>
            <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center"/>
            <Grid Grid.Column="2">
              <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
              </Grid.RowDefinitions>
              <DockPanel Grid.Row="0" DataContext="{Binding Path=ServerCollection}">
                <TextBlock DockPanel.Dock="Top" Margin="4" Text="Servers marshalling the selected interface:"/>
                <DataGrid/>
              </DockPanel>
              <GridSplitter Grid.Row="1" Height="3" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
              <DockPanel Grid.Row="2" DataContext="{Binding Path=TypeLibraryCollection}">
                <TextBlock DockPanel.Dock="Top" Margin="4" Text="Type libraries defining the selected interface:"/>
                <DataGrid/>
              </DockPanel>
            </Grid>
          </Grid>
        </TabItem>

        <TabItem Header="Type Libraries">
          <Grid DataContext="{Binding Path=TypeLibraryCollection}">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="2*"/>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <DataGrid x:Name="typeLibsGrid" Grid.Column="0" dgx:DataGridFilter.IsAutoFilterEnabled="True"/>
            <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center"/>
            <Grid Grid.Column="2">
              <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
              </Grid.RowDefinitions>
              <DockPanel Grid.Row="0" DataContext="{Binding Path=ServerCollection}">
                <TextBlock DockPanel.Dock="Top" Margin="4" Text="Servers containing the selected type library:"/>
                <DataGrid/>
              </DockPanel>
              <GridSplitter Grid.Row="1" Height="3" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
              <DockPanel Grid.Row="2" DataContext="{Binding Path=InterfaceCollection}">
                <TextBlock DockPanel.Dock="Top" Margin="4" Text="Interfaces contained in the selected type library:"/>
                <DataGrid/>
              </DockPanel>
            </Grid>
          </Grid>
        </TabItem>
      </TabControl>
      <TextBlock Text="Loading ..." HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="56" FontWeight="Bold">
      <TextBlock.Style>
        <Style TargetType="TextBlock">
          <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsLoading}" Value="False">
              <Setter Property="Visibility" Value="Hidden"/>
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </TextBlock.Style>
      </TextBlock>
    </Grid>
    <Grid VerticalAlignment="Top" HorizontalAlignment="Right" Margin="2">
      <StackPanel Orientation="Horizontal">
        <Button Content="About..." Padding="3,0" Click="about_Click"/>
        <Decorator Width="3"/>
        <ComboBox SelectedItem="{Binding RegistryView, Mode=TwoWay}">
          <x:StaticExtension Member="win32:RegistryView.Registry32"/>
          <x:StaticExtension Member="win32:RegistryView.Registry64"/>
        </ComboBox>
      </StackPanel>
    </Grid>
  </Grid>
</Window>
